package io.shallwe._admin.basedata.init;

import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import io.shallwe._admin.basedata.location.LocationService;
import io.shallwe.common.model.StaticHanger;


public class StaticHangerService {
	
	@Inject LocationService	locationService;
	
	private StaticHanger dao= new StaticHanger().dao();

	public StaticHanger findById(Integer id) {
		return dao.findById(id);
	}
	
	public Ret paginate(Integer offset,Integer pageSize) {
		Integer pageNumber=offset/pageSize+1;
		Page<Record> paginate = Db.template("initInformation.paginate").paginate(pageNumber, pageSize);
		Ret ret = Ret.by("total", paginate.getTotalRow()).set("rows", paginate.getList());
		return ret;
	}
	
	public Ret save(StaticHanger hanger) {
		int sort=getMaxSort()+1;
		hanger.setSort(sort);
		hanger.save();
		return Ret.ok("msg","操作成功");
	}

	public Ret update(StaticHanger hanger) {
		hanger.update();
		return Ret.ok("msg","操作成功");
	}
	
	public Ret delete(Integer id) {
		dao.deleteById(id);
		return Ret.ok("msg","操作成功");
	}
	
	public int getMaxSort() {
		Integer maxSort=Db.queryInt("select max(sort) from t_static_hanger");
		if(null==maxSort) {
			return 0;
		}
		return maxSort;
	}

	public Ret doLocation() {
		return Ret.ok("msg","操作成功");
	}

}
